﻿using System.Collections.Generic;
using System.IO;

namespace NExplorer.AddIns.WinRar
{
	internal class WinRarMenuBuilder : SingleCategoryMenuBuilder
	{
		private readonly List<LowerCaseString> _extractExtensions = new List<LowerCaseString>();

		public WinRarMenuBuilder()
		{
			_extractExtensions.Add(new LowerCaseString("zip"));	
			_extractExtensions.Add(new LowerCaseString("rar"));	
		}

		protected override string Category
		{
			get { return "WinRar"; }
		}

		protected override void AddCommands()
		{
			SelectionInfo selectionInfo = ServiceManager.Explorer.SelectionInfo;
			IList<FileSystemInfo> selectedItems = ServiceManager.Explorer.SelectedItems;

			// Only one file is selected and it is something we can decompress.
			if (selectedItems.Count == 1 && selectionInfo.Extensions.Count == 1 && _extractExtensions.Contains(selectionInfo.Extensions[0]))
			{
				// Add Extract Files and Extract Here
				Add<ExtractFilesCommand>();
				Add<ExtractHereCommand>();
			}
			// One or more items are selected and we can handle all of their extensions.
			else if (selectedItems.Count > 0 && _extractExtensions.ContainsAll(selectionInfo.Extensions))
			{
				Add<ExtractHereCommand>();
			}
		}
	}
}
